<?php defined('BASEPATH') or exit('No direct script access allowed');
class Plugin_Block extends Plugin
{
	public function render(){
		$html = "";
		$this->load->model('block/block_m');
		$position      = $this->attribute('position');
//		$style      = $this->attribute('style');
		$data = $this->block_m->list_postion($position);
		foreach($data as $item){
//			$a = array('parent_id'=>1);
			$item->options = json_decode($item->options);
			$style = $item->style;
			$html .= $this->$style($item);
		}
		return $html;
		
	}
	
	function style1( $data ){
//		print_r($data);
		
		$html = "";
		$this->load->model($data->module.'/'.$data->model);//categories_m
		$title = "";
		if($data->title_show == 1)
			$title = "<h3 class=\"modHead\">".$data->title."</h3>";
		
		$model = $data->model;
		$method = $data->method;
		$html .= $this->$model->$method($data->options);
		return "<div class=\"block style1 mod\">".$title."<div class=\"content modContent\">".$html.'</div></div>';
		
	}
	//menu
	function style2( $data ){
//		print_r($data);
		
		$html = "";
		$this->load->model($data->module.'/'.$data->model);//categories_m
		$title = "";		
		$model = $data->model;
		$method = $data->method;
		$html .= $this->$model->$method($data->options);
		return $html;
		
	}
	//dang title | hình ảnh | .. (block san pham)
	function style3( $data ){
		$html = "";
		$this->load->model($data->module.'/'.$data->model);
		$title = "";		
		$model = $data->model;
		$method = $data->method;
		$title = $data->title_show ? $data->title : "";
		$html .= $this->$model->$method($title,$data->options);
		return $html;
	}
	//block tim kiem
	function search( $data ){
		$html = "";
		$this->load->model($data->module.'/'.$data->model);
		$title = "";		
		$model = $data->model;
		$method = $data->method;
		$title = $data->title_show ? $data->title : "";
		$html .= $this->$model->$method($title,$data->options);
		return $html;
	}
	
	function support_online(){
		$this->load->model('support_online/support_m');
		$html = $this->support_m->block();
		return $html;
	}
}
